// Add catalog to filters
jQuery('#catalog_list').on('change', 'input', function() {
  var filters = JSON.parse(jQuery('#filters').val())

  // in this context jQuery(this) means the INPUT(checkbox) tag
  if (jQuery(this).attr('checked')) {
    
    // Generate the key name        
    var key = 'catalog_' + jQuery(this).val();
    
    // Add the catalog id to catalogs
    filters.catalogs[key] = {"id": jQuery(this).val()};

    // Save filters to INPUT #filters
    jQuery('#filters').val(JSON.stringify(filters));
  }
  else {

    // Generate the key name        
    var key = 'catalog_' + jQuery(this).val();

    // remove the element
    delete filters.catalogs[key];

    // Save filters to INPUT #filters
    jQuery('#filters').val(JSON.stringify(filters));
  }
  
}); // Change event of INPUT(checkbox)